package com.lyx.liaicodemotherbackend.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.lyx.liaicodemotherbackend.exception.BusinessException;
import com.lyx.liaicodemotherbackend.exception.ErrorCode;
import com.lyx.liaicodemotherbackend.model.dto.user.UserConfirmPasswordRequest;
import com.lyx.liaicodemotherbackend.model.dto.user.UserQueryRequest;
import com.lyx.liaicodemotherbackend.model.dto.user.UserUpdateRequest;
import com.lyx.liaicodemotherbackend.model.vo.LoginUserVO;
import com.lyx.liaicodemotherbackend.model.vo.UserVO;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.service.IService;
import com.lyx.liaicodemotherbackend.model.entity.User;
import jakarta.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户 服务层。

 */
public interface UserService extends IService<User> {
    /**
     * 用户注册
     *
     * @param userAccount   用户账户
     * @param userPassword  用户密码
     * @param checkPassword 校验密码
     * @return 新用户 id
     */
    long userRegister(String userAccount, String userPassword, String checkPassword);

    /**
     * 获取脱敏的已登录用户信息
     *
     * @return
     */
    LoginUserVO getLoginUserVO(User user);

    /**
     * 用户登录
     *
     * @param userAccount  用户账户
     * @param userPassword 用户密码
     * @param request
     * @return 脱敏后的用户信息
     */
    LoginUserVO userLogin(String userAccount, String userPassword, HttpServletRequest request);

    /**
     * 获取当前登录用户
     *
     * @param request
     * @return
     */
    User getLoginUser(HttpServletRequest request);

    /**
     * 用户注销
     *
     * @param request
     * @return
     */
    boolean userLogout(HttpServletRequest request);


    UserVO getUserVO(User user);

    List<UserVO> getUserVOList(List<User> userList);

    QueryWrapper getQueryWrapper(UserQueryRequest userQueryRequest);

    String getEncryptPassword(String defaultPassword);

    /**
     * 重置密码
     *
     * @param userConfirmPasswordRequest
     * @return
     * @author lyx
     * @create 2025/10/25
     **/
    boolean resetPassword(UserConfirmPasswordRequest userConfirmPasswordRequest);

    /**
     * 用户更新自己的信息
     *
     * @param userUpdateRequest 更新请求
     * @param request HTTP请求
     * @return 更新结果
     */
    boolean updateCurrentUser(UserUpdateRequest userUpdateRequest, HttpServletRequest request);
}
